#include "miniutil/thread.h"
#include "miniutil/sharefile.h"
#include "miniutil/threadpool.h"
#include "miniutil/random.h"

class ShareFileTest:public miniutil::runnable
{
public:
    ShareFileTest(char fillchar = 'a')
    {
        mfillchar = fillchar;
    }
    void run()
    {
        miniutil::frame::LocalSharedFile lfile;
        lfile.Open("./share.data");

        lfile.SetLength(100*1024);
        char fillbuf[1024];
        memset(fillbuf, mfillchar, sizeof(fillbuf));
        for(unsigned int i=0; i< 100; i++)
        {
            lfile.Write(fillbuf, i*1024, sizeof(fillbuf));
            //miniutil::thread::sleep(miniutil::Random::rand_value(1000));
        }
    }

    char mfillchar;
};

int main(int argc, char** argv)
{
    char fillchar = 'A';
    if(argc == 2)
        fillchar = argv[1][0];

    ShareFileTest st;
    miniutil::threadpool::RunTask(&st);
    while(true)
    {
        miniutil::thread::sleep(100);
    }
    //miniutil::frame::LocalSharedFile lfile;
    //lfile.Open("./share.data");

    //lfile.SetLength(100*1024);
    //char fillbuf[1024];
    //memset(fillbuf, fillchar, sizeof(fillbuf));
    //for(unsigned int i=0; i< 100; i++)
    //{
    //    lfile.Write(fillbuf, i*1024, sizeof(fillbuf));
    //    //miniutil::thread::sleep(miniutil::Random::rand_value(1000));
    //}
    return 0;
}
